// 导入依赖
const express = require('express')
const cfg = require('./config/config')
const mycors = require('./middleware/MyCros')
// 导入数据库处理控制器
const userController = require('./controller/userController')
const roomController = require('./controller/roomController')
const orderController = require('./controller/orderController')
const errorHandler = require('./middleware/error')
// 创建app
const app = express()
app.use(mycors)
app.use(express.json()); // 用于解析 application/json
app.use(express.urlencoded({ extended: true })); // 解析表单数据
app.use('/user', userController)
app.use('/rooms',roomController),
app.use('/orders',orderController)
// 错误处理
app.use(errorHandler);
// 定时任务 - 每30分钟检查未支付订单
setInterval(async () => {
  try {
    const Order = require('./models/Order');
    await Order.autoReleaseLockedRooms();
    console.log('自动释放锁定会议室任务执行完成');
  } catch (error) {
    console.error('定时任务执行失败:', error);
  }
}, 30 * 60 * 1000); // 30分钟
app.listen(5000, () => {
  console.log('服务已启动，监听端口5000')
})
